package Goson;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * <p>Description:</p>
 * <p>Copyright: Copyright (c)2019$</p>
 * <p>Company: Tope</p>
 * <P>Created Date :2019$-08$-12$</P>
 * <P>@version 1.0</P>
 */
class Car {
    private Long ID;
    private String name;

    public Long getID() {
        return ID;
    }

    public void setID(Long ID) {
        this.ID = ID;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return "Car{" +
                "ID=" + ID +
                ", name='" + name + '\'' +
                '}';
    }
}

public class listTest {
    public static void main(String[] args) {
        Car car = new Car();
        car.setID(4654L);
        car.setName("gaolei");
        Car car1 = new Car();

        //  List<Car> list = new ArrayList<>();
//        list.add(car);
//        list.add(car1);

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("ID", 46565L);
        // byte[] bytes= jsonObject.toString().getBytes();
        byte[] bytes = JSON.toJSONBytes(car);

        Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").create();
//        gson.fromJson(new String(bytes),ArrayList.class);
//        ArrayList list1 = new ArrayList<>();
        Car s = new Car();
        s = gson.fromJson(new String(bytes), Car.class);
//        list1.forEach(x->{
//            System.out.println(x.toString());
//        });
        //     Car car2 = (Car) list1.get(1);
        System.out.println(s);
    }
}
